
/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"6C0F6D57-CE98-4612-82E2-1F3C7728938D"}
 */
function buscarFoto(event) {
	//for the web you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
	plugins.file.showFileOpenDialog(null, null, true, new Array("Images", "jpg", "gif", "png", "*"), altaFotos, 'Seleccione las fotos')
}

/**
 * @param {Array<plugins.file.JSFile>} fotos
 * 
 * @properties={typeid:24,uuid:"96A83F7C-3A4C-4068-8780-5C3D650B62D3"}
 */
function altaFotos(fotos)
{
	for (var i = 0 ; i < fotos.length ; i++)
	{
		var $foto = fotos[i]
		var $img = plugins.images.getImage($foto.getBytes());
		tipos_habitacion_to_fotos.newRecord()
		tipos_habitacion_to_fotos.foto = $img
	}
}
/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"E101E456-C4F5-47AA-98F7-0D10EECF01B2"}
 */
function verFotos(event) {
	if (tipos_habitacion_to_fotos.getSize() == 0)
	{
		globals.DIALOGS.showWarningDialog('Aviso','No hay fotos cargadas para esta habitacion','OK')
		return 
	}
	var $win = application.createWindow('FOTOS_HAB',JSWindow.MODAL_DIALOG)
	forms.tipos_habitacion_fotos.controller.loadRecords(tipos_habitacion_to_fotos)
	forms.tipos_habitacion_fotos.controller.show($win)
}

/**
 * @properties={typeid:24,uuid:"9A75A7C7-74C2-4408-9D5E-6BF0221ED12D"}
 */
function guardar() {
	if (descripcion_corta == null || limite_adulto == null || limite_menor == null)
	{
		globals.DIALOGS.showErrorDialog('Aviso','Por favor, ingrese todos los campos obligatorios','OK')
		return false
	}
	if (valida() == false)
	{
		globals.DIALOGS.showErrorDialog('Aviso','La descripción ya existe. Por favor, ingrese otra','OK')
		return false
		
	}
	if (databaseManager.saveData() == true)
	{
		globals.DIALOGS.showInfoDialog('Aviso','Datos modificados con éxito','OK')
		return true
	}
	else
	{
		globals.DIALOGS.showWarningDialog('Aviso','Ocurrio un error al grabar. Inténtelo nuevamente', 'OK')
		return false
	}
}

/**
 * @properties={typeid:24,uuid:"BBB796AA-8C12-432D-B411-3A477E273B31"}
 */
function valida()
{
	var $sql = 'SELECT tipo_habitacion_id FROM tipos_habitacion WHERE upper(descripcion_corta) = upper(?) AND hotel_id = ? AND tipo_habitacion_id = ?'
	var $args = [descripcion_corta, globals.gHotelId, tipo_habitacion_id]
	var $ds = databaseManager.getDataSetByQuery('hoteleria',$sql,$args,-1)
	if ($ds.getMaxRowIndex() == 0)
		return true
	return false
}

/**
 * @properties={typeid:24,uuid:"AFC5F791-E920-4477-ABDC-C9FADD20A076"}
 */
function cancelar() {
	databaseManager.revertEditedRecords()
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"C4C4A653-67CE-4F93-A1B1-908CF851FE4A"}
 */
function onShow(firstShow, event) {
	databaseManager.setAutoSave(false)
}

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"1B30B50A-D05B-450C-8CB8-C70093F84664"}
 */
function onHide(event) {
	databaseManager.revertEditedRecords()
	databaseManager.setAutoSave(true)
	return true
}
